# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=SDL_ttf
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.11
pkgrel=6
pkgdesc="A library that allows you to use TrueType fonts in your SDL applications (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://libsdl.org/projects/SDL_ttf/"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
depends=("${MINGW_PACKAGE_PREFIX}-SDL"
         "${MINGW_PACKAGE_PREFIX}-freetype")
options=('staticlibs' 'strip')
source=(https://libsdl.org/projects/SDL_ttf/release/${_realname}-${pkgver}.tar.gz
        "bug1433.patch"
        "freetype-pkgconfig.patch")
sha256sums=('724cd895ecf4da319a3ef164892b72078bd92632a5d812111261cde248ebcdb7'
            '48b899d97da1fbe44c4e850e5c9781ca278b6e6f1baf43fa165f7061863940c1'
            'a2ecbd0fde86ac265bd7820ba557bb2f10fd6e3fef3156629ca14f45bd80861d')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # https://bugs.archlinux.org/task/28674
  patch -Np1 -i "${srcdir}/bug1433.patch"

  # Fix build with FreeType 2.9.1
  patch -Np1 -i "${srcdir}/freetype-pkgconfig.patch"

  touch NEWS README AUTHORS ChangeLog
  ./autogen.sh
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
